<?php

class NewsController extends Controller_Site 
{
	/**
	 * @var NewsRow
	 */
	private $newsRow;
	
	public function preDispatch()
	{
		$id = $this->_getParam('id');
		$newsRow = NewsPeer::getInstance()->find($id)->current();
		if (!$newsRow) {
			//@todo go to 404
		}
		$this->newsRow = $newsRow;
		parent::preDispatch();
	}
	
	public function indexAction()
	{
		// add news row to view
		$this->view->news = ContentListElement::fromRow($this->newsRow);
		
		// get comments
		$criteria = new CommentCriteria();
		$criteria->setSubstanceType('news');
		$criteria->setSubstanceId($this->newsRow->getId());
		$criteria->setLimit(10);
		$select = CommentService::getComments($criteria);
		$rowset = CommentPeer::getInstance()->fetchAll($select);
		$this->view->comments = ContentList::fromRowset($rowset);
	}
}